#include "threadCache.h"
static void *FetchMemoryFromCenterCache()
{
    cout << "get memory form center cache" << endl;
    return nullptr;
}
 
void *ThreadCache::Allocation(size_t size)
{
    int alignSize = Size().RoundUp(size);
    int index = Size().index(alignSize);
    if (_memorylist[index].empty())
    {
        cout << "通过上级中心申请空间" << endl;
        return FetchMemoryFromCenterCache();
    }
    else
    {
        cout << "通过回收的链表申请空间" << endl;
        return _memorylist[index].pop();
    }
}

void ThreadCache::Dealloction(void *ptr, size_t size)
{
    int alignSize = Size().RoundUp(size);
    int index = Size().index(alignSize);
    _memorylist[index].push(ptr);
}